package com.grq.mis.validate;

import com.grq.mis.entity.CertType;
import com.grq.mis.exception.BusinessException;
import com.grq.mis.exception.ResultEnum;
import org.springframework.util.StringUtils;

public class CertTypeValidate {

    public static void add(CertType certType) {

        // name
        if (StringUtils.isEmpty(certType.getName())) {
            throw new BusinessException(ResultEnum.PARAM_ERROR, "商品类型名称不能为空");
        }
        if (certType.getName().length() > 50) {
            throw new BusinessException(ResultEnum.PARAM_ERROR, "商品类型名称最多为50字");
        }

        // description
        if (!StringUtils.isEmpty(certType.getDescription())) {
            if (certType.getDescription().length() > 255) {
                throw new BusinessException(ResultEnum.PARAM_ERROR, "商品类型描述最多为255字符");
            }
        }

    }

    public static void update(CertType certType) {

        if (certType.getId() == null) {
            throw new BusinessException(ResultEnum.PARAM_ERROR, "商品类型ID不能为空");
        }

        // name
        if (StringUtils.isEmpty(certType.getName())) {
            throw new BusinessException(ResultEnum.PARAM_ERROR, "商品类型名称不能为空");
        }
        if (certType.getName().length() > 50) {
            throw new BusinessException(ResultEnum.PARAM_ERROR, "商品类型名称最多为50字");
        }

        // description
        if (!StringUtils.isEmpty(certType.getDescription())) {
            if (certType.getDescription().length() > 255) {
                throw new BusinessException(ResultEnum.PARAM_ERROR, "商品类型描述最多为255字符");
            }
        }

        if (certType.getIsDisable() == null) {
            throw new BusinessException(ResultEnum.PARAM_ERROR, "商品类型状态不能为空");
        }

    }
}
